//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<DataManager.h>
///	@path	~/src/database/
///	@date	2007/11/21
///	@desc	Data manager.

#pragma once

#include "xeres.h"

#include "lib/utilities/dir_tree.h"

#include "object/IBuffer.h"

#include "database/IData.h"

struct IStream;

namespace xeres {

	class IFile;

	/*!
		\class	DataManager
		\brief	Data manager, provide lots of function to manipulate data.
	*/
	class DataManager
	{
	protected:

		/// \name Constructor & Destructor
		//@{

		/// \ctor
		DataManager( void );

		/// \dtor
		~DataManager( void );

		//@}

	public:

		/// \name Internal Manipulation
		//@{

		///	\brief		Initialize resource center.
		bool Initialize( void );

		///	\brief		Finalize resource center.
		void Finalize( void );

		/// \brief		Determine if is initialized.
		bool IsInitialized( void );

		//@}

		/// \name Interface Manipulator
		//@{

		
		/*!
			\brief		Add data entry to root tree.
		*/
		void AddDataEntryRoot( RefWeak<IData> entry );

		/*!
			\brief		Open exist data entry.
		*/
		RefPass<IData> OpenData( const WString& path , bool create_non_exists = false );

		/*! 
			\brief		Open file.
		*/
		RefPass<IFile> OpenFile( const WString& path );

		/*! 
			\brief		Open IStream.
		*/
		IStream * OpenIStream( const WString& path );

		/*! 
			\brief		Open resource.
		*/

		/*! 
			\brief		Load binary data from file.
		*/
		RefPass<IBuffer> LoadBinaryFromFile( const WString& path );

		/*! 
			\brief		Open root data entry.
		*/
		RefWeak<IData> OpenRoot( void ) { return m_rootEntry; }

		//@}

	private:

	//@ data

		// root entry
		Ref<IData>				m_rootEntry;
	};

} // namespace xeres
